using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Script.Serialization;
using System.Collections;

namespace DynamicJsonParser
{
    class Program
    {
        static void Main(string[] args)
        {
            string demoJson = @"
{
    'lastopens':
    {
        'left':['c:\\','c:\\'],
        'right':['c:\\','c:\\windows\\']
       
    }
}
    ";
            

            var serializer = new JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic easycmd = serializer.Deserialize<object>(demoJson);
            Console.WriteLine(easycmd.lastopens.left);
            Console.WriteLine(easycmd.lastopens.right);
            Console.WriteLine(easycmd.lastopens.right[0]);
         
            Console.ReadLine();
            // create json
            dynamic easycmdObj = new DynamicJsonObject();
            dynamic lastopensObj = new DynamicJsonObject();
            ArrayList leftObj = new ArrayList();
            ArrayList rightObj = new ArrayList();
            leftObj.Add("c:\\");
            leftObj.Add("c:\\");
            rightObj.Add("c:\\windows");
            lastopensObj.left = leftObj;
            lastopensObj.right = rightObj;
            easycmdObj.lastopens = lastopensObj;
            Console.WriteLine(easycmdObj.ToString());
            Console.ReadLine();
            return;
           

            // and creating JSON formatted data

            dynamic jdata = new DynamicJsonObject();
            dynamic item1 = new DynamicJsonObject();
            dynamic item2 = new DynamicJsonObject();

            ArrayList items = new ArrayList();

            item1.Name  = "Drone";
            item1.Price = 92000.3;
            item2.Name  = "Jet";
            item2.Price = 19000000.99;

            items.Add(item1);
            items.Add(item2);

            jdata.Date  = "06/06/2004";
            jdata.Items = items;

            Console.WriteLine(jdata.ToString());
        }

    }
}
